package com.example.weatherforecast.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

import java.util.Timer;
import java.util.TimerTask;

public class UpdateTimeService extends Service {

    String TAG = "UpdateTimeService";

    @Override
    public void onCreate() {
        super.onCreate();

        //定时器每隔1秒发送一次广播
        new Timer().scheduleAtFixedRate(new TimerTask() {
            @Override
            public void run() {
                Intent timeIntent = new Intent();
                timeIntent.setAction("TIME_CHANGED_ACTION");//自定义Action
                sendBroadcast(timeIntent); //发送广播
                Log.i(TAG, "更新时间");
            }
        }, 0, 1000);
    }

    public UpdateTimeService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }
}
